package cn.sdhuijin.vms.sms.util;

import javax.swing.JOptionPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.Service.ServiceStatus;

public class SmsUtil {
	static final Logger logger = LoggerFactory.getLogger(SmsUtil.class);
	public static String notifyPhone = "";

	public static void sendMessage(String phone, String message) {
		if (Service.getInstance().getServiceStatus() == ServiceStatus.STARTED) {
			if (!"10010".equals(phone)) {
				phone = "+86" + phone;
			}
			OutboundMessage msg = new OutboundMessage(phone, message);
			msg.setEncoding(MessageEncodings.ENCUCS2);
			msg.setStatusReport(true);
			Service.getInstance().queueMessage(msg);
		} else {
			logger.info("短信猫未启动，短信不能发送.to:{} msg:{}", phone, message);
			JOptionPane.showMessageDialog(null, "短信猫未启动。", "错误",
					JOptionPane.ERROR_MESSAGE);
		}

	}
}
